package com.hex.ds.hdtp.core.web.data.table.controller;

import com.hex.bigdata.hbda.annotation.Log;
import com.hex.ds.hdtp.core.app.common.page.dto.PageDto;
import com.hex.ds.hdtp.core.app.data.table.dto.request.TableTransferFieldMapRequestDto;
import com.hex.ds.hdtp.core.app.data.table.service.ITableTransferFieldMapService;
import com.hex.ds.hdtp.core.web.common.page.PageVo;
import com.hex.ds.hdtp.core.web.common.page.converter.IPageVoAndPageDtoConverter;
import com.hex.ds.hdtp.core.web.data.table.converter.ITableTransferFieldMapVoConverter;
import com.hex.ds.hdtp.core.web.data.table.vo.TableTransferFieldMapVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Package com.hex.ds.hdtp.core.web.data.table.controller
 * @ClassName TableTransferFieldMapController
 * @Description 表迁移清单字段映射-WEB接口
 * @Author Wang zhihao
 * @Date 2023/8/9 13:48
 * @Version v1.0
 **/
@Slf4j
@RestController
@Api(tags = "01-表迁移：字段映射")
@RequestMapping("/api/data/table/fieldMap")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TableTransferFieldMapController {

    private final ITableTransferFieldMapService tableTransferFieldMapService;

    private final ITableTransferFieldMapVoConverter converter;

    private final IPageVoAndPageDtoConverter pageVoAndPageDtoConverter;

    /**
     * @param tableTransferFieldMapVo
     * @param pageVo
     * @Method queryListByPage
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移清单字段映射-分页查询
     * @Author Wang zhihao
     * @Date 2023/8/9 13:45
     * @Version V1.0
     */
    @GetMapping
    @ApiOperation("表迁移清单字段映射-分页查询")
    public ResponseEntity queryListByPage(TableTransferFieldMapVo tableTransferFieldMapVo, PageVo pageVo) {
        log.debug("进入到【TableTransferFieldMapController.queryListByPage】方法,参数：{}" + tableTransferFieldMapVo.toString());
        final PageDto pageDto = pageVoAndPageDtoConverter.toPageDto(pageVo);
        TableTransferFieldMapRequestDto requestDto = converter.toRequestDto(tableTransferFieldMapVo);
        return ResponseEntity.ok(tableTransferFieldMapService.queryListByPage(requestDto, pageDto));
    }

    /**
     * @param tableTransferFieldMapVo
     * @Method add
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移清单字段映射-新增
     * @Author Wang zhihao
     * @Date 2023/8/9 13:46
     * @Version V1.0
     */
    @Log("表迁移清单字段映射-新增")
    @PostMapping
    @ApiOperation("表迁移清单字段映射-新增")
    public ResponseEntity add(@RequestBody TableTransferFieldMapVo tableTransferFieldMapVo) {
        log.info("进入到【TableTransferFieldMapController.add】方法,参数：{}", tableTransferFieldMapVo.toString());
        tableTransferFieldMapService.add(converter.toRequestDto(tableTransferFieldMapVo));
        return ResponseEntity.ok("新增成功");
    }

    /**
     * @param tableTransferFieldMapVo
     * @Method update
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移清单字段映射-更新
     * @Author Wang zhihao
     * @Date 2023/8/9 13:47
     * @Version V1.0
     */
    @PutMapping
    @ApiOperation("表迁移清单字段映射-更新")
    public ResponseEntity update(@RequestBody TableTransferFieldMapVo tableTransferFieldMapVo) {
        log.info("进入到【TableTransferFieldMapController.update】方法,参数：{}", tableTransferFieldMapVo.toString());
        tableTransferFieldMapService.modifyById(converter.toRequestDto(tableTransferFieldMapVo));
        return ResponseEntity.ok("更新成功");
    }

    /**
     * @param pkIds
     * @Method delete
     * @Param
     * @Return org.springframework.http.ResponseEntity
     * @Description 表迁移清单字段映射-批量删除
     * @Author Wang zhihao
     * @Date 2023/8/9 10:42
     * @Version V1.0
     */
    @Log("表迁移清单字段映射-批量删除")
    @DeleteMapping(value = {"/{pkIds}"})
    @ApiOperation("表迁移清单字段映射-批量删除")
    public ResponseEntity delete(@PathVariable("pkIds") @NotNull List<String> pkIds) {
        log.info("进入【TableTransferFieldMapController.delete】方法,参数：{}", pkIds);
        tableTransferFieldMapService.batchRemoveById(pkIds);
        return ResponseEntity.ok("删除成功");
    }

}
